// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyavtSimulationInformation.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <PyavtSimulationCommandSpecification.h>
#include <PyavtSimulationCommandSpecification.h>

// ****************************************************************************
// Module: PyavtSimulationInformation
//
// Purpose:
//   Contains information about simulation connections
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a avtSimulationInformation.
//
struct avtSimulationInformationObject
{
    PyObject_HEAD
    avtSimulationInformation *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewavtSimulationInformation(int);
std::string
PyavtSimulationInformation_ToString(const avtSimulationInformation *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%shost = \"%s\"\n", prefix, atts->GetHost().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sport = %d\n", prefix, atts->GetPort());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%ssecurityKey = \"%s\"\n", prefix, atts->GetSecurityKey().c_str());
    str += tmpStr;
    {   const stringVector &otherNames = atts->GetOtherNames();
        snprintf(tmpStr, 1000, "%sotherNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < otherNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", otherNames[i].c_str());
            str += tmpStr;
            if(i < otherNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &otherValues = atts->GetOtherValues();
        snprintf(tmpStr, 1000, "%sotherValues = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < otherValues.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", otherValues[i].c_str());
            str += tmpStr;
            if(i < otherValues.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    { // new scope
        int index = 0;
        // Create string representation of genericCommands from atts.
        for(AttributeGroupVector::const_iterator pos = atts->GetGenericCommands().begin(); pos != atts->GetGenericCommands().end(); ++pos, ++index)
        {
            const avtSimulationCommandSpecification *current = (const avtSimulationCommandSpecification *)(*pos);
            snprintf(tmpStr, 1000, "GetGenericCommands(%d).", index);
            std::string objPrefix(prefix + std::string(tmpStr));
            str += PyavtSimulationCommandSpecification_ToString(current, objPrefix.c_str(), forLogging);
        }
        if(index == 0)
            str += "#genericCommands does not contain any avtSimulationCommandSpecification objects.\n";
    }
    const char *mode_names = "Unknown, Running, Stopped";
    switch (atts->GetMode())
    {
      case avtSimulationInformation::Unknown:
          snprintf(tmpStr, 1000, "%smode = %sUnknown  # %s\n", prefix, prefix, mode_names);
          str += tmpStr;
          break;
      case avtSimulationInformation::Running:
          snprintf(tmpStr, 1000, "%smode = %sRunning  # %s\n", prefix, prefix, mode_names);
          str += tmpStr;
          break;
      case avtSimulationInformation::Stopped:
          snprintf(tmpStr, 1000, "%smode = %sStopped  # %s\n", prefix, prefix, mode_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    { // new scope
        int index = 0;
        // Create string representation of customCommands from atts.
        for(AttributeGroupVector::const_iterator pos = atts->GetCustomCommands().begin(); pos != atts->GetCustomCommands().end(); ++pos, ++index)
        {
            const avtSimulationCommandSpecification *current = (const avtSimulationCommandSpecification *)(*pos);
            snprintf(tmpStr, 1000, "GetCustomCommands(%d).", index);
            std::string objPrefix(prefix + std::string(tmpStr));
            str += PyavtSimulationCommandSpecification_ToString(current, objPrefix.c_str(), forLogging);
        }
        if(index == 0)
            str += "#customCommands does not contain any avtSimulationCommandSpecification objects.\n";
    }
    snprintf(tmpStr, 1000, "%smessage = \"%s\"\n", prefix, atts->GetMessage().c_str());
    str += tmpStr;
    return str;
}

static PyObject *
avtSimulationInformation_Notify(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_SetHost(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the host in the object.
    obj->data->SetHost(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetHost(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetHost().c_str());
    return retval;
}

/*static*/ PyObject *
avtSimulationInformation_SetPort(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the port in the object.
    obj->data->SetPort(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetPort(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetPort()));
    return retval;
}

/*static*/ PyObject *
avtSimulationInformation_SetSecurityKey(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the securityKey in the object.
    obj->data->SetSecurityKey(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetSecurityKey(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetSecurityKey().c_str());
    return retval;
}

/*static*/ PyObject *
avtSimulationInformation_SetOtherNames(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetOtherNames() = vec;
    // Mark the otherNames in the object as modified.
    obj->data->SelectOtherNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetOtherNames(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    // Allocate a tuple the with enough entries to hold the otherNames.
    const stringVector &otherNames = obj->data->GetOtherNames();
    PyObject *retval = PyTuple_New(otherNames.size());
    for(size_t i = 0; i < otherNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(otherNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
avtSimulationInformation_SetOtherValues(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetOtherValues() = vec;
    // Mark the otherValues in the object as modified.
    obj->data->SelectOtherValues();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetOtherValues(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    // Allocate a tuple the with enough entries to hold the otherValues.
    const stringVector &otherValues = obj->data->GetOtherValues();
    PyObject *retval = PyTuple_New(otherValues.size());
    for(size_t i = 0; i < otherValues.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(otherValues[i].c_str()));
    return retval;
}

/*static*/ PyObject *
avtSimulationInformation_GetGenericCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    int index = -1;
    if (args == NULL)
        return PyErr_Format(PyExc_NameError, "Use .GetGenericCommands(int index) to get a single entry");
    if (!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "arg must be a single integer index");
    if (index < 0 || (size_t)index >= obj->data->GetGenericCommands().size())
        return PyErr_Format(PyExc_ValueError, "index out of range");

    // Since the new object will point to data owned by the this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyavtSimulationCommandSpecification_Wrap(&obj->data->GetGenericCommands(index));
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyavtSimulationCommandSpecification_SetParent(retval, self);

    return retval;
}

PyObject *
avtSimulationInformation_GetNumGenericCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    return PyInt_FromLong((long)obj->data->GetGenericCommands().size());
}

PyObject *
avtSimulationInformation_AddGenericCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *element = NULL;
    if(!PyArg_ParseTuple(args, "O", &element))
        return NULL;
    if(!PyavtSimulationCommandSpecification_Check(element))
        return PyErr_Format(PyExc_TypeError, "expected attr object of type avtSimulationCommandSpecification");
    avtSimulationCommandSpecification *newData = PyavtSimulationCommandSpecification_FromPyObject(element);
    obj->data->AddGenericCommands(*newData);
    obj->data->SelectGenericCommands();
    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
avtSimulationInformation_Remove_One_GenericCommands(PyObject *self, int index)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    // Remove in the AttributeGroupVector instead of calling RemoveGenericCommands() because we don't want to delete the object; just remove it.
    AttributeGroupVector &atts = obj->data->GetGenericCommands();
    AttributeGroupVector::iterator pos = atts.begin();
    // Iterate through the vector "index" times.
    for(int i = 0; i < index; ++i)
        ++pos;

    // If pos is still a valid iterator, remove that element.
    if(pos != atts.end())
    {
        // NOTE: Leak the object since other Python objects may reference it. Ideally,
        // we would put the object into some type of pool to be cleaned up later but
        // this will do for now.
        //
        // delete *pos;
        atts.erase(pos);
    }

    obj->data->SelectGenericCommands();
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject *
avtSimulationInformation_RemoveGenericCommands(PyObject *self, PyObject *args)
{
    int index = -1;
    if(!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "Expecting integer index");
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    if(index < 0 || index >= obj->data->GetNumGenericCommands())
        return PyErr_Format(PyExc_IndexError, "Index out of range");

    return avtSimulationInformation_Remove_One_GenericCommands(self, index);
}

PyObject *
avtSimulationInformation_ClearGenericCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    int n = obj->data->GetNumGenericCommands();
    for(int i = 0; i < n; ++i)
    {
        avtSimulationInformation_Remove_One_GenericCommands(self, 0);
        Py_DECREF(Py_None);
    }
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_SetMode(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid mode value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Unknown";
        ss << ", Running";
        ss << ", Stopped";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the mode in the object.
    obj->data->SetMode(avtSimulationInformation::RunMode(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetMode(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMode()));
    return retval;
}

/*static*/ PyObject *
avtSimulationInformation_GetCustomCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    int index = -1;
    if (args == NULL)
        return PyErr_Format(PyExc_NameError, "Use .GetCustomCommands(int index) to get a single entry");
    if (!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "arg must be a single integer index");
    if (index < 0 || (size_t)index >= obj->data->GetCustomCommands().size())
        return PyErr_Format(PyExc_ValueError, "index out of range");

    // Since the new object will point to data owned by the this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyavtSimulationCommandSpecification_Wrap(&obj->data->GetCustomCommands(index));
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyavtSimulationCommandSpecification_SetParent(retval, self);

    return retval;
}

PyObject *
avtSimulationInformation_GetNumCustomCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    return PyInt_FromLong((long)obj->data->GetCustomCommands().size());
}

PyObject *
avtSimulationInformation_AddCustomCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *element = NULL;
    if(!PyArg_ParseTuple(args, "O", &element))
        return NULL;
    if(!PyavtSimulationCommandSpecification_Check(element))
        return PyErr_Format(PyExc_TypeError, "expected attr object of type avtSimulationCommandSpecification");
    avtSimulationCommandSpecification *newData = PyavtSimulationCommandSpecification_FromPyObject(element);
    obj->data->AddCustomCommands(*newData);
    obj->data->SelectCustomCommands();
    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
avtSimulationInformation_Remove_One_CustomCommands(PyObject *self, int index)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    // Remove in the AttributeGroupVector instead of calling RemoveCustomCommands() because we don't want to delete the object; just remove it.
    AttributeGroupVector &atts = obj->data->GetCustomCommands();
    AttributeGroupVector::iterator pos = atts.begin();
    // Iterate through the vector "index" times.
    for(int i = 0; i < index; ++i)
        ++pos;

    // If pos is still a valid iterator, remove that element.
    if(pos != atts.end())
    {
        // NOTE: Leak the object since other Python objects may reference it. Ideally,
        // we would put the object into some type of pool to be cleaned up later but
        // this will do for now.
        //
        // delete *pos;
        atts.erase(pos);
    }

    obj->data->SelectCustomCommands();
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject *
avtSimulationInformation_RemoveCustomCommands(PyObject *self, PyObject *args)
{
    int index = -1;
    if(!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "Expecting integer index");
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    if(index < 0 || index >= obj->data->GetNumCustomCommands())
        return PyErr_Format(PyExc_IndexError, "Index out of range");

    return avtSimulationInformation_Remove_One_CustomCommands(self, index);
}

PyObject *
avtSimulationInformation_ClearCustomCommands(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    int n = obj->data->GetNumCustomCommands();
    for(int i = 0; i < n; ++i)
    {
        avtSimulationInformation_Remove_One_CustomCommands(self, 0);
        Py_DECREF(Py_None);
    }
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_SetMessage(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the message in the object.
    obj->data->SetMessage(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSimulationInformation_GetMessage(PyObject *self, PyObject *args)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetMessage().c_str());
    return retval;
}



PyMethodDef PyavtSimulationInformation_methods[AVTSIMULATIONINFORMATION_NMETH] = {
    {"Notify", avtSimulationInformation_Notify, METH_VARARGS},
    {"SetHost", avtSimulationInformation_SetHost, METH_VARARGS},
    {"GetHost", avtSimulationInformation_GetHost, METH_VARARGS},
    {"SetPort", avtSimulationInformation_SetPort, METH_VARARGS},
    {"GetPort", avtSimulationInformation_GetPort, METH_VARARGS},
    {"SetSecurityKey", avtSimulationInformation_SetSecurityKey, METH_VARARGS},
    {"GetSecurityKey", avtSimulationInformation_GetSecurityKey, METH_VARARGS},
    {"SetOtherNames", avtSimulationInformation_SetOtherNames, METH_VARARGS},
    {"GetOtherNames", avtSimulationInformation_GetOtherNames, METH_VARARGS},
    {"SetOtherValues", avtSimulationInformation_SetOtherValues, METH_VARARGS},
    {"GetOtherValues", avtSimulationInformation_GetOtherValues, METH_VARARGS},
    {"GetGenericCommands", avtSimulationInformation_GetGenericCommands, METH_VARARGS},
    {"GetNumGenericCommands", avtSimulationInformation_GetNumGenericCommands, METH_VARARGS},
    {"AddGenericCommands", avtSimulationInformation_AddGenericCommands, METH_VARARGS},
    {"RemoveGenericCommands", avtSimulationInformation_RemoveGenericCommands, METH_VARARGS},
    {"ClearGenericCommands", avtSimulationInformation_ClearGenericCommands, METH_VARARGS},
    {"SetMode", avtSimulationInformation_SetMode, METH_VARARGS},
    {"GetMode", avtSimulationInformation_GetMode, METH_VARARGS},
    {"GetCustomCommands", avtSimulationInformation_GetCustomCommands, METH_VARARGS},
    {"GetNumCustomCommands", avtSimulationInformation_GetNumCustomCommands, METH_VARARGS},
    {"AddCustomCommands", avtSimulationInformation_AddCustomCommands, METH_VARARGS},
    {"RemoveCustomCommands", avtSimulationInformation_RemoveCustomCommands, METH_VARARGS},
    {"ClearCustomCommands", avtSimulationInformation_ClearCustomCommands, METH_VARARGS},
    {"SetMessage", avtSimulationInformation_SetMessage, METH_VARARGS},
    {"GetMessage", avtSimulationInformation_GetMessage, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
avtSimulationInformation_dealloc(PyObject *v)
{
   avtSimulationInformationObject *obj = (avtSimulationInformationObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *avtSimulationInformation_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyavtSimulationInformation_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "host") == 0)
        return avtSimulationInformation_GetHost(self, NULL);
    if(strcmp(name, "port") == 0)
        return avtSimulationInformation_GetPort(self, NULL);
    if(strcmp(name, "securityKey") == 0)
        return avtSimulationInformation_GetSecurityKey(self, NULL);
    if(strcmp(name, "otherNames") == 0)
        return avtSimulationInformation_GetOtherNames(self, NULL);
    if(strcmp(name, "otherValues") == 0)
        return avtSimulationInformation_GetOtherValues(self, NULL);
    if(strcmp(name, "genericCommands") == 0)
        return avtSimulationInformation_GetGenericCommands(self, NULL);
    if(strcmp(name, "mode") == 0)
        return avtSimulationInformation_GetMode(self, NULL);
    if(strcmp(name, "Unknown") == 0)
        return PyInt_FromLong(long(avtSimulationInformation::Unknown));
    if(strcmp(name, "Running") == 0)
        return PyInt_FromLong(long(avtSimulationInformation::Running));
    if(strcmp(name, "Stopped") == 0)
        return PyInt_FromLong(long(avtSimulationInformation::Stopped));

    if(strcmp(name, "customCommands") == 0)
        return avtSimulationInformation_GetCustomCommands(self, NULL);
    if(strcmp(name, "message") == 0)
        return avtSimulationInformation_GetMessage(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyavtSimulationInformation_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyavtSimulationInformation_methods[i].ml_name),
                PyString_FromString(PyavtSimulationInformation_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyavtSimulationInformation_methods, self, name);
}

int
PyavtSimulationInformation_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "host") == 0)
        obj = avtSimulationInformation_SetHost(self, args);
    else if(strcmp(name, "port") == 0)
        obj = avtSimulationInformation_SetPort(self, args);
    else if(strcmp(name, "securityKey") == 0)
        obj = avtSimulationInformation_SetSecurityKey(self, args);
    else if(strcmp(name, "otherNames") == 0)
        obj = avtSimulationInformation_SetOtherNames(self, args);
    else if(strcmp(name, "otherValues") == 0)
        obj = avtSimulationInformation_SetOtherValues(self, args);
    else if(strcmp(name, "mode") == 0)
        obj = avtSimulationInformation_SetMode(self, args);
    else if(strcmp(name, "message") == 0)
        obj = avtSimulationInformation_SetMessage(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
avtSimulationInformation_print(PyObject *v, FILE *fp, int flags)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)v;
    fprintf(fp, "%s", PyavtSimulationInformation_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
avtSimulationInformation_str(PyObject *v)
{
    avtSimulationInformationObject *obj = (avtSimulationInformationObject *)v;
    return PyString_FromString(PyavtSimulationInformation_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *avtSimulationInformation_Purpose = "Contains information about simulation connections";
#else
static char *avtSimulationInformation_Purpose = "Contains information about simulation connections";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(avtSimulationInformationType,         \
                  "avtSimulationInformation",           \
                  avtSimulationInformationObject,       \
                  avtSimulationInformation_dealloc,     \
                  avtSimulationInformation_print,       \
                  PyavtSimulationInformation_getattr,   \
                  PyavtSimulationInformation_setattr,   \
                  avtSimulationInformation_str,         \
                  avtSimulationInformation_Purpose,     \
                  avtSimulationInformation_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
avtSimulationInformation_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &avtSimulationInformationType
         || Py_TYPE(other) != &avtSimulationInformationType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    avtSimulationInformation *a = ((avtSimulationInformationObject *)self)->data;
    avtSimulationInformation *b = ((avtSimulationInformationObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static avtSimulationInformation *defaultAtts = 0;
static avtSimulationInformation *currentAtts = 0;

static PyObject *
NewavtSimulationInformation(int useCurrent)
{
    avtSimulationInformationObject *newObject;
    newObject = PyObject_NEW(avtSimulationInformationObject, &avtSimulationInformationType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new avtSimulationInformation(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new avtSimulationInformation(*defaultAtts);
    else
        newObject->data = new avtSimulationInformation;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapavtSimulationInformation(const avtSimulationInformation *attr)
{
    avtSimulationInformationObject *newObject;
    newObject = PyObject_NEW(avtSimulationInformationObject, &avtSimulationInformationType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (avtSimulationInformation *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
avtSimulationInformation_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewavtSimulationInformation(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef avtSimulationInformationMethods[] = {
    {"avtSimulationInformation", avtSimulationInformation_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *avtSimulationInformationObserver = 0;

std::string
PyavtSimulationInformation_GetLogString()
{
    std::string s("avtSimulationInformation = avtSimulationInformation()\n");
    if(currentAtts != 0)
        s += PyavtSimulationInformation_ToString(currentAtts, "avtSimulationInformation.", true);
    return s;
}

static void
PyavtSimulationInformation_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("avtSimulationInformation = avtSimulationInformation()\n");
        s += PyavtSimulationInformation_ToString(currentAtts, "avtSimulationInformation.", true);
        cb(s);
    }
}

void
PyavtSimulationInformation_StartUp(avtSimulationInformation *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyavtSimulationInformation_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(avtSimulationInformationObserver == 0)
    {
        avtSimulationInformationObserver = new ObserverToCallback(subj,
            PyavtSimulationInformation_CallLogRoutine, (void *)data);
    }

}

void
PyavtSimulationInformation_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete avtSimulationInformationObserver;
    avtSimulationInformationObserver = 0;
}

PyMethodDef *
PyavtSimulationInformation_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return avtSimulationInformationMethods;
}

bool
PyavtSimulationInformation_Check(PyObject *obj)
{
    return (obj->ob_type == &avtSimulationInformationType);
}

avtSimulationInformation *
PyavtSimulationInformation_FromPyObject(PyObject *obj)
{
    avtSimulationInformationObject *obj2 = (avtSimulationInformationObject *)obj;
    return obj2->data;
}

PyObject *
PyavtSimulationInformation_New()
{
    return NewavtSimulationInformation(0);
}

PyObject *
PyavtSimulationInformation_Wrap(const avtSimulationInformation *attr)
{
    return WrapavtSimulationInformation(attr);
}

void
PyavtSimulationInformation_SetParent(PyObject *obj, PyObject *parent)
{
    avtSimulationInformationObject *obj2 = (avtSimulationInformationObject *)obj;
    obj2->parent = parent;
}

void
PyavtSimulationInformation_SetDefaults(const avtSimulationInformation *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new avtSimulationInformation(*atts);
}

